ShadowDrawable

This class is a thin wrapper around the library's core draw functionalities, allowing its shadows to be drawn manually without having to use the core module directly.

Clipped instances with irregular shapes on API levels 30+ must have the outline Path set manually using the setClipPathProvider function. This is analogous to setting a ViewPathProvider on a target View.

The user is responsible for invalidating the current draw whenever a property's value is changed. Failure to do so can result in a few different possible defects, depending on the specific setup, including misaligned clip regions, stale draws, etc.

The color compat functionality is exposed here through the colorCompat property, which is set to black by default, disabling the compat tinting. Setting any non-black color enables color compat, and the ambientColor and spotColor values are then ignored.

Color compat requires an owner View in order to be able to hook into the hardware-accelerated draw routine, and that View must be attached to the onscreen hierarchy. Instances created with the @RequiresApi(29) constructor will throw an IllegalStateException upon attempts to modify colorCompat.

Color compat shadows are always clipped to the drawable's bounds.

Normally the owner is just the View in which the draw happens, though that's not strictly necessary. However, due to a limitation in the core graphics framework, the color compat mechanism needs to track its onscreen location, and the lighting effects may go out of sync with the expected appearance if the drawing View moves differently than the owner.

All ShadowDrawable instances created with an owner should call dispose. This is technically not necessary for the @RequiresApi(29) ones, but it is still safe to call dispose on those instances. Use after disposal is not an automatic Exception, but it is not advised, and there is no guaranteed behavior.

The Drawable class's required setColorFilter override is a no-op here.

Constructors

Link copied to clipboard
constructor(owner: View, isClipped: Boolean)

The base constructor for all API levels requires an owner View that must be attached to the onscreen hierarchy.

@RequiresApi(value = 29)
constructor(isClipped: Boolean)

At API level 29, an owner View is not required, but color compat is unavailable for these instances.

Properties

Link copied to clipboard
open override var alpha: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Determines whether the shadow will be clipped to the drawable's bounds.

Link copied to clipboard

The color that the compat mechanism uses to tint the shadow. The default value is black (#FF000000), which disables the tint. If any other color is set, the compat mechanism takes over, and the ambient and spot values are ignored.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val current: Drawable
Link copied to clipboard
open val dirtyBounds: Rect
Link copied to clipboard
Link copied to clipboard

Flag to indicate whether the library shadow should always be composited through a layer, regardless of the color compat state.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var level: Int
Link copied to clipboard
open val minimumHeight: Int
Link copied to clipboard
open val minimumWidth: Int
Link copied to clipboard
open override val opacity: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open var state: IntArray
Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun clearColorFilter()
Link copied to clipboard
fun copyBounds(bounds: Rect)
Link copied to clipboard
fun dispose()

Releases any active internal resources.

Link copied to clipboard
open override fun draw(canvas: Canvas)
Link copied to clipboard
open override fun getAlpha(): Int

Analogous to RenderNode#getAlpha(), but returns an Int to conform to Drawable's API.

Link copied to clipboard
open fun getHotspotBounds(outRect: Rect)
Link copied to clipboard
Link copied to clipboard
fun getMatrix(outMatrix: Matrix)
Link copied to clipboard
open override fun getOpacity(): Int
Link copied to clipboard
open fun getOutline(outline: Outline)
Link copied to clipboard
open fun getPadding(padding: Rect): Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun inflate(r: Resources, parser: XmlPullParser, attrs: AttributeSet)
open fun inflate(r: Resources, parser: XmlPullParser, attrs: AttributeSet, theme: Resources.Theme?)
Link copied to clipboard
open fun invalidateSelf()
Link copied to clipboard
Link copied to clipboard
open fun mutate(): Drawable
Link copied to clipboard
open fun onLayoutDirectionChanged(layoutDirection: Int): Boolean
Link copied to clipboard
open fun scheduleSelf(what: Runnable, when: Long)
Link copied to clipboard
open override fun setAlpha(alpha: Int)

Analogous to RenderNode#setAlpha(), but takes an Int to conform to Drawable's API.

Link copied to clipboard
fun setClipPathProvider(provider: (Path) -> Unit?)

Sets the function through which to provide irregular Paths for clipping on API levels 30 and above.

Link copied to clipboard
open fun setColorFilter(color: Int, mode: PorterDuff.Mode)
open override fun setColorFilter(colorFilter: ColorFilter?)
Link copied to clipboard
open fun setDither(dither: Boolean)
Link copied to clipboard
open fun setHotspot(x: Float, y: Float)
Link copied to clipboard
open fun setHotspotBounds(left: Int, top: Int, right: Int, bottom: Int)
Link copied to clipboard
fun setOutline(outline: Outline)
Link copied to clipboard
open fun setTint(tintColor: Int)
Link copied to clipboard
open fun setTintBlendMode(blendMode: BlendMode?)
Link copied to clipboard
open fun setTintList(tint: ColorStateList?)
Link copied to clipboard
open fun setTintMode(tintMode: PorterDuff.Mode?)
Link copied to clipboard
open fun setVisible(visible: Boolean, restart: Boolean): Boolean
Link copied to clipboard
open fun unscheduleSelf(what: Runnable)